<%@page import="shoppingmall.jmu.cart.entity.Cart"%>
<%@page import="shoppingmall.jmu.cart.dao.impl.CartDAOImpl"%>
<%@page import="shoppingmall.jmu.cart.dao.CartDAO"%>
<%@page import="shoppingmall.jmu.good.entity.Goods"%>
<%@page import="shoppingmall.jmu.good.dao.impl.GoodsDAOImpl"%>
<%@page import="shoppingmall.jmu.good.dao.GoodsDAO"%>
<%@page import="shoppingmall.jmu.orderitem.dao.impl.OrderItemDAOImpl"%>
<%@page import="shoppingmall.jmu.orderitem.dao.OrderItemDAO"%>
<%@page import="shoppingmall.jmu.order.dao.impl.OrderDAOImpl"%>
<%@page import="shoppingmall.jmu.order.dao.OrderDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String user_id = "12345678901";
	String[] cartNo = request.getParameterValues("cartNo");
	
	String order_id = request.getParameter("orderId");
	
	String number = request.getParameter("address");
	int address_id = Integer.parseInt(number);
	
	String pay = request.getParameter("payment");
	double payment = Float.parseFloat(pay);
	System.out.print(pay);
	
	OrderItemDAO odi = new OrderItemDAOImpl();
	GoodsDAO gd = new GoodsDAOImpl();
	CartDAO cd = new CartDAOImpl();
	
	
	OrderDAO od = new OrderDAOImpl();
	int odResult = 0;
	odResult = od.addOrderByUserId(user_id, order_id, address_id, payment);
	
	int odiResult = 0;
	int cdResult = 0;
	for(String cn : cartNo){
		Goods g = gd.getGoodsByID(cn);
		Cart c = cd.getOneCart(user_id, cn);
		
		
		double price = g.getPrice();
		int count = c.getCount();
		
		odiResult = odi.addOrderItem(cn, price, count, order_id);	//添加到用户订单
		
		cdResult= cd.deleteCert(user_id, cn);	//删除购物车内容
	}
	
	
	response.sendRedirect("pay-success.jsp?order_id="+order_id+"&payment="+pay);
	
%>